<?php

class Caf_xls extends Controller
{

	function index()
	{
	
	}
//to upload xls file and read content of it....
	function caf_xls()
	{
		
		parent::Controller();
		
		
		$this->load->helper('url');
		$this->load->helper('form');
		$this->load->library('form_validation');
		ini_set("display_errors",1);
		error_reporting(E_ALL);
	
		$displayform ='';
		$displayform .='<div id=dashboard ><span>Data Entry</span> <a href='.base_url().'/idea_home/dashboard ><img align=right src="'.base_url().'images/home.png" alt="home" /></a><img align=right src="'.base_url().'images/back.png" id="back"" alt="back" ONCLICK="history.go(-1)" /></div>';
		$displayform .= '<div id=upload>';
		$attr = array('class'=>'add_outward','id'=>'add_upload');
		$displayform .= form_open_multipart('index.php/caf_xls/save_xls',$attr);
	    	
 	    	
	    	$displayform .= '<fieldset id="legendstyle">';
	    	$displayform .= ' <legend id="legendtext">Please select file to upload</legend>';
	    	$displayform .= '<center><table cellspacing="20px"><tr>';
	    	
		
		$displayform .= '<tr><td align=left>select a file to upload <em> * </em></td>';
		$displayform .= '<td align=left><input type="file" name="userfile" size="20" class="required" accept="xls" />';
		$displayform .= '</td></tr>';

		$displayform .='<tr><td colspan=2 align=center><input class="submit" type="submit" value="Upload Excel Sheet"/>';
		$displayform .='</td></tr></table></center>';
$displayform .= '</fieldset><div align="right"><input type=button value="Go Back" ONCLICK="history.go(-1)" /></form></div>';
		
		
		
		$this->template->add_js('js/jquery-latest.js');	
		$this->template->add_js('js/jquery.validate.js');
		$this->template->add_js('js/validate_xls.js');
		$this->template->add_js('$(document).ready(function(){
	 		   $("#add_xls").validate();
	  			});
		','embed');
		$data = array('formdisplay'=>$displayform);

			$this->template->write_view('header','header', $data, True);
			$this->template->write_view('content', 'other_general');
			$this->template->render();
		}
		
	

		
	function save_outward()
		{
		
		 	
			$dir = './uploads/420/';

			 if (!is_dir($dir)) { 
	               		 $theupload_path = mkdir( $dir , 0777);
			}

		$config['upload_path'] = $dir;
		$config['allowed_types'] = 'xls';
		$config['max_size']	= '2097152';
		$config['max_width']  = '1024';
		$config['max_height']  = '768';


		$this->load->library('upload',$config);
				
		if (!$this->upload->do_upload()) 
				{
					$error = array('error' => $this->upload->display_errors());
					print_r($error);
				}    
				else
				{	
					$filename = array('upload_data' => $this->upload->data());
				
					require_once 'excel_reader2.php';
          
          $data = new Spreadsheet_Excel_Reader('./cafuploads/'.$file_name);
          echo $data->dump(true,true);
					//$this->load->model('unclaimmed_model');
				//	$this->unclaimmed_model->insert_unclaimed($filename['upload_data']['file_name']);
										
				}
				
		}
		
	    
	
}

